// pages/my/xitonglog/index.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
      list:[],
      pagenum:1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
    getDataList:function(e){
    var that = this;
        wx.request({
            url:app.data.server + '/index.php/Tongcheng/Book/getXitonLogList',
            data:{
                pagenum:that.data.pagenum,
                uid:getApp().globalData.userInfo.uid
            },
            success:function(d){
                // console.log(JSON.stringify(d.data));
                that.setData({
                    list:d.data
                })
            }
        });
    },
    delLog:function(e){
      var that = this;
      var id = e.currentTarget.dataset.id;
        wx.showModal({
            title:'提示',
            content:'确定要删除吗？',
            showCancel:true,
            success:function(res){
                if (res.confirm) {
                    wx.request({
                        url:getApp().data.server+'/index.php/Tongcheng/Book/delXiTongLog?id='+id,
                        success:res=>{
                            if(0 == res.data){
                                wx.showToast({
                                    title:'确认失败',
                                    icon: 'success',
                                    duration: 2000
                                })
                            }else{
                                wx.showToast({
                                    title:'确认成功',
                                    icon: 'success',
                                    duration: 2000
                                })
                            }
                            setTimeout(function(){
                                that.setData({
                                    list:[],
                                    pagenum:1
                                })
                                that.getDataList();
                            },1000)

                        }
                    });
                }
            }
        })
    },

    //去详情
    toinfo:function(e){
      var type = e.currentTarget.dataset.type;
      var oid = e.currentTarget.dataset.oid;
      var buy = e.currentTarget.dataset.buy;
      var goods_id = e.currentTarget.dataset.goods_id;
      var id = e.currentTarget.dataset.id;
      var goodoid = e.currentTarget.dataset.goodoid;
      var mlog = e.currentTarget.dataset.mlog;
      var path = '';
      //更新系统通知为已读
        var that = this;
        wx.request({
            url:app.data.server + '/index.php/Tongcheng/Book/readXiTong?id='+id
        });
        if(1 == parseInt(mlog)){
            wx.navigateTo({
                url: '/pages/my/xitonglog/info?id='+id
            })
            return;
        }
          if(1 == parseInt(type) || 6 == parseInt(type)){
              //闲置
              path = '/pages/order/orderInfoMai?id='+oid;
          }else{
              //图书
              path = '/pages/find/sureJieMai?id='+goods_id;
              if(0 == goodoid || null == goodoid){
                  path = '/pages/order/orderInfo?id='+oid
              }
          }
      wx.navigateTo({
        url: path
      })
    },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
      var that = this;
      that.setData({
          list:[],
          pagenum:1
      })
      that.getDataList();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})